//
//  TopView.m
//  WashForU
//
//  Created by 王俊 on 15/11/29.
//  Copyright © 2015年 王俊. All rights reserved.
//

#import "TopView.h"

@implementation TopView

+(instancetype)initWithContact:(Contact*) person
{
    TopView *view                     = [[TopView alloc]init];
    UILabel *nameLabel                = [[UILabel alloc]init];
    UILabel *phoneNumb                = [[UILabel alloc]init];
    UILabel *headerOfMyCode           = [[UILabel alloc]init];
    UILabel *myCode                   = [[UILabel alloc]init];
    UILabel *numbOfCodeLeftLabel      = [[UILabel alloc]init];
    UIImageView *userImage            = [[UIImageView alloc]init];
    UIImageView *phoneImage           = [[UIImageView alloc]init];
    UIImageView *verticalSeparateLine = [[UIImageView alloc]init];
    UIImageView *horizenSeparateLine  = [[UIImageView alloc]init];
    
    nameLabel.text             = person.name;
    phoneNumb.text             = person.phoneNumb;
    headerOfMyCode.text        = @"推荐码:";
    myCode.text                = person.code;
    numbOfCodeLeftLabel.text   = [NSString stringWithFormat:@"余%@张洗衣券",person.numbOfCodeLeft];
    userImage.image            = [UIImage imageNamed:@"用户图标"];
    phoneImage.image           = [UIImage imageNamed:@"手机图标"];
    verticalSeparateLine.image = [UIImage imageNamed:@"蓝底竖线"];
    horizenSeparateLine.image  = [UIImage imageNamed:@"蓝底横线"];
    
    view.backgroundColor               = [UIColor clearColor];
    nameLabel.textColor                = [UIColor whiteColor];
    phoneNumb.textColor                = [UIColor whiteColor];
    headerOfMyCode.textColor           = [UIColor whiteColor];
    myCode.textColor                   = [UIColor whiteColor];
    numbOfCodeLeftLabel.textColor      = [UIColor whiteColor];
    
    nameLabel.font              = [UIFont CustomFont:18];
    phoneNumb.font              = [UIFont CustomFont:18];
    headerOfMyCode.font         = [UIFont CustomFont:16];
    numbOfCodeLeftLabel.font    = [UIFont CustomFont:16];
    myCode.font                 = [UIFont boldSystemFontOfSize:16];
    
    nameLabel.textAlignment           = NSTextAlignmentLeft;
    phoneNumb.textAlignment           = NSTextAlignmentLeft;
    numbOfCodeLeftLabel.textAlignment = NSTextAlignmentLeft;
    headerOfMyCode.textAlignment      = NSTextAlignmentRight;
    myCode.textAlignment              = NSTextAlignmentLeft;
    
    [view addSubview:nameLabel];
    [view addSubview:phoneNumb];
    [view addSubview:headerOfMyCode];
    [view addSubview:myCode];
    [view addSubview:userImage];
    [view addSubview:phoneImage];
    [view addSubview:numbOfCodeLeftLabel];
    [view addSubview:verticalSeparateLine];
    [view addSubview:horizenSeparateLine];
    
    [userImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(30, 30));
        make.leading.equalTo(view).offset(30);
        make.top.equalTo(view).offset(50);
    }];
    [phoneImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.leading.equalTo(userImage);
        make.top.equalTo(userImage.mas_bottom).offset(20);
    }];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.height.equalTo(userImage);
        make.width.mas_equalTo(SCREENWIDTH/2);
        make.leading.equalTo(userImage.mas_trailing).offset(3);
    }];
    [phoneNumb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.leading.equalTo(nameLabel);
        make.centerY.equalTo(phoneImage);
    }];
    [horizenSeparateLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(view).offset(15);
        make.size.mas_equalTo(CGSizeMake(SCREENWIDTH - 30, 15));
        make.bottom.bottom.equalTo(view).offset(-50);
    }];
    [verticalSeparateLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(view);
        make.size.mas_equalTo(CGSizeMake(15, 40));
        make.top.equalTo(horizenSeparateLine.mas_bottom).offset(5);
    }];
    [myCode mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(60, 30));
        make.trailing.equalTo(verticalSeparateLine.mas_leading).offset(-15);
        make.top.equalTo(horizenSeparateLine).offset(20);
    }];
    [headerOfMyCode mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.centerY.equalTo(myCode);
        make.trailing.equalTo(myCode.mas_leading);
    }];
    [numbOfCodeLeftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(verticalSeparateLine.mas_trailing).offset(20);
        make.width.mas_equalTo(90);
        make.centerY.height.equalTo(myCode);
    }];

    
    
    
    return view;
}


@end
